package com.yq.leetcodeOld.stack;

import java.util.Stack;

/**
 * @ClassName Solution232
 * @Description TODO
 * @Author yaoqiang
 * @Date 2022/3/25 11:08
 * @Version 1.0
 * stack by list 用两个栈s1s2, 以s1为基准，
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */
public class Solution232 {
    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.push(1);
        myQueue.push(2);
        int a = myQueue.pop();
        int b = myQueue.peek();
        boolean c = myQueue.empty();
        System.out.println(a + ",,,,," + b + "      " + c);}
}
class MyQueue{
    private Stack<Integer> s1,s2;private int front;
    public MyQueue(){s1=new Stack<>();s2=new Stack<>();}
    public void push(int x){
        if (s1.isEmpty()){front=x;}
        while(!s1.isEmpty()){
            s2.push(s1.pop());
        }
        s1.push(x);
        while (!s2.isEmpty()){
            s1.push(s2.pop());
        }
    }
    public int  peek(){return s1.peek();}
    public  int pop(){ int res= s1.pop(); if (!s1.isEmpty()){front=s1.peek();} return  res;}
    public  boolean empty(){return s1.empty();}
}
